<template>
  <div class="body">
    <van-nav-bar fixed z-index="11">
      <template #left>
        <i
          class="iconfont icon-fanhui"
          style="font-size: 20px; font-weight: 600"
          @click="$router.back()"
        ></i>
      </template>
      <template #title>
        <span style="font-size: 20px; font-weight: 600">我的关注</span>
      </template>
    </van-nav-bar>
    <div class="bbox" v-if="content.length">
      <div class="peoples" v-for="(i, index) in content" :key="index">
        <img :src="i.avatar | picUrl" alt="" />
        <div class="user">
          <span class="username">{{ i.username }}</span>
          <span class="occu">{{ i.occupation }} · <span v-if="i.location">{{i.location.country.name}}</span> · 粉丝 {{i.count.count_follower}}</span>
        </div>
        <div
          @click.stop="attentions(i.id)"
          class="guanzhu"
          v-if="attentionList.indexOf(i.id) == -1"
        >
          关注
        </div>
        <div
          @click.stop="attentions(i.id)"
          class="guanzhu guanzhued"
          v-else
        >
          已关注
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  data() {
    return {
      attention: [],
      content: [],
    };
  },
  created() {
    this.getContent();
  },
  computed:{
      ...mapState(['attentionList'])
  },
  methods: {
    attentions(id) {
      this.$store.commit("addAttention", { id: id });
    },
    getContent() {
      if (this.attentionList != 0) {
        this.attentionList.forEach((a) => {
          this.axios
            .get("https://apis.netstart.cn/xpc/user/" + a)
            .then((res) => {
              this.content.push(res.data.data);
            });
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.body{
    width: 100vw;
    height: 100vh;
    background-color: #fff;
}
.bbox {
    padding: 0 20px;
    padding-top: 50px;
  .peoples {
    border-top: 1px solid #f0f0f0;
    width: 100%;
    height: 80px;
    padding: 10px;
    display: flex;
    align-items: center;
    &:first-of-type{
        border: none;
    }
    &:last-of-type{
        border-bottom: 1px solid #f0f0f0;
    }
    img {
      width: 45px;
      height: 45px;
      border-radius: 50%;
      margin-right: 10px;
    }
    .user {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      height: 44px;
      .username {
        font-weight: 600;
      }
      .occu {
        font-size: 12px;
        color: #999;
      }
    }
    .guanzhu {
      width: 80px;
      padding: 5px 15px;
      border-radius: 26px;
      font-weight: 500;
      text-align: center;
      color: #e76961;
      background-color: #fbeee8;
      &.guanzhued {
        background-color: #ddd;
        color: #888;
      }
    }
  }
}
</style>